package com.mentaleye.dal.dao.mybatis;

import com.mentaleye.dal.dao.CurriculumDao;
import com.mentaleye.dal.model.Curriculum;
import com.mentaleye.dal.model.CurriculumExample;
import com.mentaleye.dal.service.CurriculumMapper;
import com.mentaleye.enums.CommonStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class CurriculumDaoImpl extends BaseDao implements CurriculumDao {

	@Autowired
	private CurriculumMapper curriculumMapper;

	public boolean addCurriculum(Curriculum curriculum) {
		return getResultByInt(curriculumMapper.insertSelective(curriculum));
	}

	public boolean editCurriculum(Curriculum curriculum) {
		return getResultByInt(curriculumMapper.updateByPrimaryKeySelective(curriculum));
	}

	@Override
	public Curriculum getCurriculumByNo(Integer curriculumNo) {
		return curriculumMapper.selectByPrimaryKey(curriculumNo);
	}

	public List<Map<String, Object>> queryCurriculum(String curriculumName, List<String> cotainNos, List<String> unCotainNos,
													 String readyRelate, String noRelate) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("curriculumName", curriculumName);
		map.put("cotainNos", cotainNos);
		map.put("unCotainNos", unCotainNos);
		map.put("readyRelate", readyRelate);
		map.put("noRelate", noRelate);
		return curriculumMapper.selectByMap(map);
	}

	public List<Curriculum> queryCurriculum(CurriculumExample example) {
		example.createCriteria().andCurriculumStatusNotEqualTo(CommonStatus.DELETE.getCode());
		return curriculumMapper.selectByExample(example);
	}

	public List<Map<String, Object>> queryCurriculum(Map<String, Object> map) {
		return curriculumMapper.selectByMap(map);
	}

	public boolean deleteCurriculum(List<Integer> ids) {
		if (ids == null || ids.size() == 0) return false;
		CurriculumExample example = new CurriculumExample();
		example.createCriteria().andCurriculumNoIn(ids);
		Curriculum record=new Curriculum();
		record.setCurriculumStatus(CommonStatus.DELETE.getCode());
		int rows = curriculumMapper.updateByExampleSelective( record,example);
		return rows == ids.size();
	}
}

	